package com.tutu.controller.backend;

import com.tutu.controller.common.CommonController;
import com.tutu.service.DeviceService;
import com.tutu.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据管理
 */
@Controller
@RequestMapping(value = "backend/data")
public class DataController extends CommonController {

    public static Map<String, Integer> deviceCodeDictStatusMap = new HashMap<>();

    @Autowired
    DeviceService deviceService;

    @RequestMapping(value = "/index")
    public String index() {
        return "backend/data/list";
    }

    @RequestMapping("/list")
    public void list(HttpServletResponse response, String deviceCode, Integer type, String searchDate, String keyWord, Integer draw, Integer start, Integer length) {
        int pageNum = getPageNum(start, length);

        Map<String, Object> result = deviceService.pageByParams(deviceCode, type, searchDate, keyWord, pageNum, length);

        result.put("draw", draw);

        WebUtil.printJson(response, result);
    }

    @RequestMapping("/batchUpdateStatus")
    @ResponseBody
    public Map<String, Object> batchUpdateStatus(HttpServletRequest request, String deviceCode, String type, Integer status) {
        return deviceService.batchUpdateStatus(request, deviceCode, type, status);
    }
}
